<template>
  <div class="app-container">
    <el-table ref="table" v-loading="listLoading" :data="list" border stripe style="width: 100%;" height="715">
      <el-table-column label="ID序号" prop="id" width="50px" align="center"></el-table-column>
      <el-table-column label="服务器" prop="sname" width="70px" align="center"></el-table-column>
      <el-table-column label="角色ID" prop="actor_id" align="center" width="100px"></el-table-column>
      <el-table-column label="角色名" prop="actor_name" width="100px" align="center"></el-table-column>
      <el-table-column label="等级" prop="level" width="50px" align="center"></el-table-column>
      <el-table-column label="VIP" prop="vip_level" width="40px" align="center"></el-table-column>
      <el-table-column label="充值金额" prop="amount" width="70px" align="center"></el-table-column>
      <el-table-column label="钻石" prop="diamond" width="90px" align="center"></el-table-column>
      <el-table-column label="触发规则类型" width="90px" align="center">
        <template slot-scope="{row}">
          <span v-if="row.rule_type === 1">关键词</span>
          <span v-else-if="row.rule_type === 2">连续发言</span>
          <span v-else>私聊人数</span>
        </template>
      </el-table-column>
      <el-table-column label="规则ID" prop="rule_id" width="60px" align="center"></el-table-column>
      <el-table-column label="触发内容" prop="content" align="center"></el-table-column>
      <el-table-column label="惩罚方式" align="center" width="70px">
        <template slot-scope="{row}">
          <span v-if="row.punish_type === 1">禁言</span>
          <span v-else-if="row.punish_type === 2">封账号</span>
          <span v-else>无感禁言</span>
        </template>
      </el-table-column>
      <el-table-column label="惩罚时间" prop="punish_time" width="70px" align="center"></el-table-column>
      <el-table-column label="执行时间" prop="start_dt" width="140px" align="center"></el-table-column>
      <el-table-column label="结束时间" prop="end_dt" width="140px" align="center"></el-table-column>
      <el-table-column align="center" label="操作" width="60px">
        <template slot-scope="{row}">
          <el-button v-if="checkPermission(permissionRoles.monitor_unban) && row.status == 1" type="text" size="small" @click="handleUnban(row)">解禁</el-button>
          <span v-else>已解禁</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission' // 权限判断函数
import waves from '@/directive/waves' // 实现点击波浪纹
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { getMonitorLog, unbanActor } from '@/api/chat'

export default {
  name: 'MonitorLog',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      permissionRoles: this.$store.state.user.permissionRoles,
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 200
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    checkPermission,
    async getList() {
      const query = this.listQuery
      this.listLoading = true
      const res = await getMonitorLog(query)
      this.listLoading = false
      this.list = res.data.items
      this.total = res.data.total
    },
    handleFilter() {
      this.getList()
    },
    handleUnban(row) {
      this.$confirm('你确定要解禁此玩家吗?', '解禁', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async() => {
          await unbanActor(row)
          this.getList()
          this.$message({
            type: 'success',
            message: '解禁成功!'
          })
        })
        .catch(err => { console.error(err) })
    }
  }
}
</script>
